<template>
  <div class="my-love">
    <header>
      <i @click="back"></i>
      <div class="title">我的收藏</div>
    </header>

    <main>
      <div class="num">{{num}}篇文章</div>

      <div class="content">
        <ul>
          <li v-for="d in dataArr" :key="d.id" @click="goToHomeItem(d.id)">
            <van-image fit="cover" width="100" height="100" :src="d.src" />
          </li>
        </ul>
      </div>
    </main>
  </div>
</template>

<script   setup lang="ts">
import { ref, computed, onMounted } from 'vue';
import router from '@/router';
import { usePiniaStore } from "@/stores/index";
import { storeToRefs } from 'pinia';

const piniaStore = usePiniaStore()
// const { myLike } = storeToRefs(piniaStore)

let dataArr = ref<Array<any>>([])

const back = () => {
  router.back();
}

const goToHomeItem = (id: number) => {
  router.push({
    name: "item",
    query: {
      id
    }
  });
}

const num = computed(() => {
  return dataArr.value.length;
})

onMounted(() => {
  dataArr.value = piniaStore.myCollection
})

</script>

<style lang="scss" scoped>
.my-love {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  overflow: auto;
  z-index: 100;
  background-color: #fff;

  header {
    width: 58vw;
    height: 44px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    i {
      width: 15px;
      height: 15px;
      margin: 0 10px;
      display: block;
      background-repeat: no-repeat;
      background-position: center center;
      background-size: contain;
      background-image: url("@/assets/images/user/icon_back.png");
    }

    .title {
      font-size: 18px;
      font-weight: 700;
    }
  }

  main {
    .num {
      font-size: 16px;
      margin: 10px;
    }
    .content {
      ul {
        width: 94vw;
        margin: 0 auto;
        display: flex;
        flex-flow: row wrap;
        justify-content: space-between;
        align-items: center;
        li {
          width: 30%;
          padding: 5px;
          img {
            width: 100px;
            height: 100px;
          }
        }
      }
    }
  }
}
</style>